{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1236
  Verdict: Accepted
}
uses SysUtils, Math;
 
const
     p:int64=16380;
     ton:int64=1000000;
 
 
var
   i,n:longint;
   a:array[0..1010] of extended;
   t:array[0..1010] of string;
   s:String;
 
procedure sort(l,r:longint);
var
   i,j:longint;
   x:extended;
   ys:string;
   y:extended;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
      while a[i]<x do inc(i);
      while a[j]>x do dec(j);
      if i<=j then begin
         ys:=t[i];
         t[i]:=t[j];
         t[j]:=ys;
         y:=a[i];
         a[i]:=a[j];
         a[j]:=y;
         inc(i);
         dec(j);
      end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do begin
    readln(s);
    t[i]:=s;
    a[i]:=strtoint(copy(s,1,pos(' ',s)-1));
    delete(s,1,pos(' ',s));
    s:=trim(s);
    if length(s)=2 then begin
       if s[2]='p' then a[i]:=a[i]*p else
       if s[2]='t' then a[i]:=a[i]*ton;
       if s[1]='m' then a[i]:=a[i]*(1e-3) else
       if s[1]='M' then a[i]:=a[i]*(1e6) else
       if s[1]='k' then a[i]:=a[i]*(1e3) else
       if s[1]='G' then a[i]:=a[i]*(1e9);
    end else begin
       if s[1]='p' then a[i]:=a[i]*p else
       if s[1]='t' then a[i]:=a[i]*ton;
    end;
end;
sort(1,n);
for i:=1 to n do
    writeln(t[i]);
end.